package leetcode17

var digitMap = map[int32][]byte{
	'2': []byte{'a', 'b', 'c'},
	'3': []byte{'d', 'e', 'f'},
	'4': []byte{'g', 'h', 'i'},
	'5': []byte{'j', 'k', 'l'},
	'6': []byte{'m', 'n', 'o'},
	'7': []byte{'p', 'q', 'r', 's'},
	'8': []byte{'t', 'u', 'v'},
	'9': []byte{'w', 'x', 'y', 'z'},
}

var result = make([]string, 0)

func letterCombinations(digits string) []string {
	if len(digits) == 0 {
		return []string{}
	}
	result = make([]string, 0)
	bytes := make([][]byte, 0, len(digits))
	for _, b := range digits {
		bytes = append(bytes, digitMap[b])
	}
	letterBuild([]byte{}, bytes, len(bytes))
	return result
}

func letterBuild(pre []byte, bytes [][]byte, n int) {
	if len(bytes) == 0 {
		result = append(result, string(pre))
		return
	}
	for _, b := range bytes[0] {
		letterBuild(append(pre, b), bytes[1:], n)
	}
}
